package com.heima.controller;

import com.heima.pojo.dto.PartnerDTO;
import com.heima.pojo.dto.PartnerQueryDTO;
import com.heima.pojo.vo.PartnerVO;
import com.heima.pojo.vo.TbSkuPageVO;
import com.heima.service.PartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user-service/partner")
public class PartnerController {
    @Autowired
    private PartnerService partnerService;

    @PostMapping
    public boolean addPartner(@RequestBody PartnerDTO partnerDTO){
        try {
            return partnerService.addPartner(partnerDTO);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("添加合作伙伴失败: " + e.getMessage());
        }
    }
    @GetMapping("/search")
    public TbSkuPageVO search(PartnerQueryDTO partnerQueryDTO){

        return partnerService.search(partnerQueryDTO);
    }
    @GetMapping("/{id}")
    public PartnerVO getPartnerById(@PathVariable("id") String id){
        return partnerService.getPartnerById(id);
    }
    @PutMapping("/{id}")
    public boolean updatePartner(@PathVariable("id") String id, @RequestBody PartnerDTO partnerDTO){
        try {
            return partnerService.updatePartner(id, partnerDTO);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("更新合作伙伴失败: " + e.getMessage());
        }
    }
    @DeleteMapping("/{id}")
    public boolean deletePartner(@PathVariable("id") String id){
        try {
            return partnerService.deletePartner(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("删除合作伙伴失败: " + e.getMessage());
        }
    }
}